import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_shop_z/config/service_url.dart';
import 'package:flutter_shop_z/pages/details_page.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

//首页轮播图
class SiwperDiy extends StatelessWidget {
  final List swiperDataList; //图片地址数组
  //构造器
  SiwperDiy({this.swiperDataList});

  @override
  Widget build(BuildContext context) {
    // ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);

    return Container(
      height: ScreenUtil().setHeight(333),
      width: ScreenUtil().setWidth(750),
      child: Swiper(
        itemBuilder: (BuildContext context, int index) {
          var commodity = swiperDataList[index];
          String imgUrl =
              "${serviceUrl}goods/${commodity['categoryId']}/${commodity['categorySubId']}/${commodity['commodityImg']}";
          return InkWell(
            onTap: () {
              print(commodity['commodityName']);
              Navigator.push(context, MaterialPageRoute(builder: (context) {
                return new DetailsPage(commodity['commodityId']);
              }));
            },
            child: Image.network("${imgUrl}", fit: BoxFit.fill),
          );
        },
        itemCount: swiperDataList.length,
        pagination: new SwiperPagination(
          builder: new DotSwiperPaginationBuilder(
            color: Color.fromRGBO(255, 255, 255, 1.0),
            activeColor: Color.fromRGBO(156, 39, 176, 1.0),
          ),
        ),
        autoplay: true,
      ),
    );
  }
}
